package com.example.util.page;

import java.util.Collections;
import java.util.List;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.metadata.IPage;

public class Pager<T> {

	private List<T> rows = Collections.emptyList();

	/**
	 * 总条数
	 */
	private long total;

	/**
	 * 每页显示多少条
	 */
	private long pageSize=10;

	/**
	 * 总页数
	 */
	private long totalPage;
	/**
	 * 当前页
	 */
	private long pageNum=1;


	/**
	 * 检索对象
	 */
	private JSONObject searchParams;




	public Pager() {

	}

	public Pager(IPage<T> page) {
		this.rows = page.getRecords();
		this.total = page.getTotal();
		this.pageNum = page.getCurrent();
		this.pageSize = page.getSize();
		this.totalPage = page.getPages();
	}

	public List<T> getRows() {
		return rows;
	}

	public long getTotal() {
		return total;
	}

	public long getPageSize() {
		return pageSize;
	}

	public long getTotalPage() {
		return totalPage;
	}

	public long getPageNum() {
		return pageNum;
	}

	public Pager<T> setRows(List<T> rows) {
		this.rows = rows;
		return this;
	}

	public Pager<T> setTotal(long total) {
		this.total = total;
		return this;
	}

	public Pager<T> setPageSize(long pageSize) {
		this.pageSize = pageSize;
		return this;
	}

	public Pager<T> setTotalPage(long totalPage) {
		this.totalPage = totalPage;
		return this;
	}

	public Pager<T> setPageNum(long pageNum) {
		this.pageNum = pageNum;
		return this;
	}


	public JSONObject getSearchParams() {
		return searchParams;
	}

	public void setSearchParams(JSONObject searchParams) {
		this.searchParams = searchParams;
	}


	public void  convertPage(IPage<T> page){
		this.rows = page.getRecords();
		this.total = page.getTotal();
		this.pageNum = page.getCurrent();
		this.pageSize = page.getSize();
		this.totalPage = page.getPages();
	}


}
